<template>
  <div class="app-container">


    <span :style="{ fontSize: '24px' }">{{ departmentName }} <br>{{ name }} 医生的接诊台</span>
    <br><br><br><br>
    <span>
    <el-radio-group v-model="status" @change="getConsultStatus">
      <el-radio :label="1">开启问诊</el-radio>
      <el-radio :label="0">关闭问诊</el-radio>
    </el-radio-group>
    </span>
    <br><br>


    <el-tabs v-model="activeName">
      <el-tab-pane label="已处理" name="first">

        <el-table
          v-loading="listLoading"
          :data="listHasDeal"
          element-loading-text="Loading"
          border
          fit
          highlight-current-row
        >
          <el-table-column align="center" label="ID" width="95">
            <template slot-scope="scope">
              {{ scope.row.id }}
            </template>
          </el-table-column>
          <el-table-column label="患者名称">
            <template slot-scope="scope">
              {{ scope.row.patientName }}
            </template>
          </el-table-column>
          <el-table-column label="医生名称" width="110" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.doctorName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="科室名称" width="110" align="center">
            <template slot-scope="scope">
              {{ scope.row.departmentName }}
            </template>
          </el-table-column>
          <el-table-column label="订单号" width="110" align="center">
            <template slot-scope="scope">
              {{ scope.row.orderSn }}
            </template>
          </el-table-column>
          <el-table-column label="下单日期" width="110" align="center">
            <template slot-scope="scope">
              {{ scope.row.date }}
            </template>
          </el-table-column>
          <el-table-column label="状态" width="110" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.status===2" style="color: deepskyblue">订单已处理</span>
            </template>
          </el-table-column>
          <el-table-column label="价格" width="110" align="center">
            <template slot-scope="scope">
              {{ scope.row.totalPrice }}
            </template>
          </el-table-column>
          <el-table-column label="备注" width="110" align="center">
            <template slot-scope="scope">
              {{ scope.row.node }}
            </template>
          </el-table-column>
          <el-table-column label="详情" width="110" align="center">
            <template slot-scope="scope">
              <el-button type="primary" size="mini" @click="getDetail(scope.row.id)">查看详情</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>



      <el-tab-pane label="待处理" name="second">
        <el-table
          v-loading="listLoading"
          :data="listNotDeal"
          element-loading-text="Loading"
          border
          fit
          highlight-current-row
        >
          <el-table-column align="center" label="ID" width="95">
            <template slot-scope="scope">
              {{ scope.row.id }}
            </template>
          </el-table-column>
          <el-table-column label="患者名称">
            <template slot-scope="scope">
              {{ scope.row.patientName }}
            </template>
          </el-table-column>
          <el-table-column label="医生名称" width="110" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.doctorName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="科室名称" width="110" align="center">
            <template slot-scope="scope">
              {{ scope.row.departmentName }}
            </template>
          </el-table-column>
          <el-table-column label="订单号" width="110" align="center">
            <template slot-scope="scope">
              {{ scope.row.orderSn }}
            </template>
          </el-table-column>
          <el-table-column label="下单日期" width="110" align="center">
            <template slot-scope="scope">
              {{ scope.row.date }}
            </template>
          </el-table-column>
          <el-table-column label="状态" width="110" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.status===2" style="color: red">订单还未处理</span>
            </template>
          </el-table-column>
          <el-table-column label="价格" width="110" align="center">
            <template slot-scope="scope">
              {{ scope.row.totalPrice }}
            </template>
          </el-table-column>
          <el-table-column label="备注" width="110" align="center">
            <template slot-scope="scope">
              {{ scope.row.node }}
            </template>
          </el-table-column>
          <el-table-column label="操作" width="110" align="center">
            <template slot-scope="scope">
              <el-button type="primary" size="mini" @click="startConsult(scope.row.id)">开启会诊</el-button>
            </template>
          </el-table-column>
        </el-table>

      </el-tab-pane>
    </el-tabs>

  </div>
</template>

<script>
import { getList } from '@/api/table'
import {getConsultRecord, getDepartmentInfo, getDoctorInfoById, startConsult, updStatus} from "@/api/doctor";
import {mapGetters} from "vuex";

export default {

  computed: {
    ...mapGetters([
      'name'
    ])
  },
  // filters: {
  //   statusFilter(status) {
  //     const statusMap = {
  //       published: 'success',
  //       draft: 'gray',
  //       deleted: 'danger'
  //     }
  //     return statusMap[status]
  //   }
  // },
  data() {
    return {
      list: [],
      departmentId:'',
      id:'',
      listLoading:true,
      status: 0,
      departmentName:'',
      listHasDeal:[],
      listNotDeal:[],
      activeName:'second'
    }
  },
  created() {
    this.id = localStorage.getItem('id');
    this.getDoctorInfo()
    this.departmentId = localStorage.getItem('departmentId');

    this.getConsultRecord()
    this.getDepartmentName()
  },
  methods: {

    /**
     * 查看详情
     */
    getDetail(){
      this.$message.warning("还没有开放此功能,敬请期待")
    },



    /**
     * 获取医生的信息
     */
    getDoctorInfo(){
      getDoctorInfoById(this.id).then(res=>{
        this.status = res.data.status
      })
    },
    /**
     * 开启会诊
     */
    startConsult(consultId){
      startConsult(consultId).then(res=>{
        //跳转到聊天页面
        this.$router.push({name:"ChatRoom",params:{"consultId":consultId}})
      })
    },
    /**
     * 获取科室名称
     */
    getDepartmentName(){
      getDepartmentInfo(this.departmentId).then(res=>{
        this.departmentName = res.data.departmentName
      })
    },

    /**
     * 修改医生的问诊状态
     */
    getConsultStatus(){
      updStatus(this.status).then(res=>{
        this.$message.success(res.msg)
      })
    },

    getConsultRecord(){
      getConsultRecord(this.departmentId).then(response => {
        this.listLoading = false,
        this.list = response.data
        this.list.forEach(item=>{
          if(item.status == 1){
            this.listNotDeal.push(item)
          }
          if(item.status == 2){
            this.listHasDeal.push(item)
          }
          console.log(this.listNotDeal)
        })
      })
    }


  }
}
</script>
